package com.xiaoyi.intentsdklibrary.SDK.FloatView;

import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import com.lkx.liandianqinew.R;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.xiaoyi.intentsdklibrary.Utils.StateBarUtil;

public class RectViewSDK {
    private static final RectViewSDK ourInstance = new RectViewSDK();
    private Handler mHandler;
    private WindowManager.LayoutParams mParams;
    private Runnable mR;
    private View mView;
    private WindowManager mWindowManager;

    public static RectViewSDK getInstance() {
        return ourInstance;
    }

    private RectViewSDK() {
    }

    public void init(Context context) {
        try {
            if (this.mWindowManager == null) {
                this.mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                View view = new View(context);
                this.mView = view;
                view.setBackgroundResource(R.drawable.red_rect_border);
                this.mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                this.mParams = layoutParams;
                layoutParams.height = -2;
                this.mParams.width = -2;
                this.mParams.flags = 152;
                this.mParams.format = -3;
                if (Build.VERSION.SDK_INT >= 26) {
                    this.mParams.type = 2038;
                } else {
                    this.mParams.type = 2003;
                }
                this.mParams.gravity = 8388659;
                this.mParams.x = 0;
                this.mParams.y = 0 - StateBarUtil.getStatusBarHeight(context);
                this.mParams.width = 0;
                this.mParams.height = 0;
                this.mWindowManager.addView(this.mView, this.mParams);
                View view2 = this.mView;
                if (view2 != null) {
                    view2.setVisibility(View.GONE);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void show(Context context, int i, int i2, int i3, int i4) {
        try {
            if (ActionNormalSDK.getInstance().isScreenPortrait(context)) {
                this.mParams.x = i;
                this.mParams.y = i2 - StateBarUtil.getStatusBarHeight(context);
            } else {
                this.mParams.x = i - StateBarUtil.getStatusBarHeight(context);
                this.mParams.y = i2;
            }
            this.mParams.width = i3;
            this.mParams.height = i4;
            this.mWindowManager.updateViewLayout(this.mView, this.mParams);
            this.mView.setVisibility(View.VISIBLE);
            this.mView.postDelayed(new Runnable() {
                /* class com.xiaoyi.intentsdklibrary.SDK.FloatView.RectViewSDK.AnonymousClass1 */

                public void run() {
                    RectViewSDK.this.mView.setVisibility(View.GONE);
                }
            }, 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void hide() {
        try {
            this.mView.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
